
#include "GoToCellDialog.h"
#include "qlabel.h"
#include "qlineedit.h"
#include "QPushButton.h"
#include <QHBoxLayout>
#include "QLayoutItem.h"
#include "QMessageBox.h"
#include "QRegExp.h"
#include "QValidator.h"

GoToCellDialog::GoToCellDialog(QWidget* parent/* =0 */)
	:QDialog(parent)
{
	setFixedSize(260,80);
	
	m_pLabelLocation = new QLabel(tr("&Cell Location:"),this);

	m_pLineEdit = new QLineEdit(this);
	QRegExp regExp("[A-Za-z][1-9][0-9]{0,2}");
	m_pLineEdit->setValidator(new QRegExpValidator(regExp,this));

	m_pPushBtnOK = new QPushButton(tr("OK"),this);
	m_pPushBtnOK->setDefault(true);
	m_pPushBtnOK->setEnabled(false);

	m_pPushBtnCancel = new QPushButton(tr("Cancel"),this);

	QObject::connect(m_pLineEdit,SIGNAL(textChanged(const QString &)),
					this,SLOT(slotTextChanged()));
	QObject::connect(m_pPushBtnOK,SIGNAL(clicked()),
					this,SLOT(accept()));
	QObject::connect(m_pPushBtnCancel,SIGNAL(clicked()),
					this,SLOT(reject()));



	QHBoxLayout *pHTopLayout = new QHBoxLayout();
	pHTopLayout->addWidget(m_pLabelLocation);
	pHTopLayout->addWidget(m_pLineEdit);

	QSpacerItem *pHorSpace = new QSpacerItem(80,20);
	QHBoxLayout *pHDownLayout = new QHBoxLayout();
	pHDownLayout->addItem(pHorSpace);
	pHDownLayout->addWidget(m_pPushBtnOK);
	pHDownLayout->addWidget(m_pPushBtnCancel);

	QVBoxLayout *pMainLayout = new QVBoxLayout(this);
	pMainLayout->addLayout(pHTopLayout);
	pMainLayout->addLayout(pHDownLayout);
	setLayout(pMainLayout);
}

GoToCellDialog::~GoToCellDialog()
{

}

void GoToCellDialog::slotTextChanged()
{
	//QMessageBox::information(this,"info","TextChanged");
	m_pPushBtnOK->setEnabled(m_pLineEdit->hasAcceptableInput());
}

QString GoToCellDialog::getEditText()
{
	return m_pLineEdit->text().toUpper();
}






